<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('服务类型列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>name：</label>
                            <input type="text" name="svtypeName"/>
                        </li>
                        <li>
                            状态：<select name="svtypeStatus" th:with="type=${@dict.getType('sys_appr_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:style="${dict.dictValue=='6'}?'display:none':' '"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:svtype:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:svtype:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:svtype:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-info single disabled" onclick="approve()" shiro:hasPermission="system:svtype:approve">
                <i class="fa fa-bell"></i> 审核
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:svtype:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:svtype:remove')}]];
    var approveFlag = [[${@permission.hasPermi('system:svtype:approve')}]];
    var svtypeStatusDatas = [[${@dict.getType('sys_appr_status')}]];
    var prefix = ctx + "system/svtype";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "服务类型",
            sortName: "createTime",
            sortOrder: "desc",
            columns: [{
                checkbox: true
            },
                {
                    field: 'svtypeId',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'svtypeName',
                    title: 'name'
                },
                {
                    field: 'svtypeDescription',
                    title: '描述'
                },
                {
                    field: 'svtypeStatus',
                    title: '状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(svtypeStatusDatas, value);
                    }
                },
                {
                    field: 'createBy',
                    title: '创建者'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    // align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        var edit = '<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.svtypeId + '\')"><i class="fa fa-edit"></i>编辑</a> ';
                        var remove = '<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.svtypeId + '\')"><i class="fa fa-remove"></i>删除</a>';
                        var approve = '<a class="btn btn-info btn-xs ' + approveFlag + '" href="javascript:void(0)" onclick="approve(\'' + row.svtypeId + '\')"><i class="fa fa-bell"></i>审核</a>';
                        if (row.svtypeStatus != 2){
                            actions.push(edit);
                        }
                        if(row.svtypeStatus != 0 && row.svtypeStatus != 1) {
                            actions.push(approve);
                        }
                        actions.push(remove);
                        return actions.join(' ');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 审核 */
    function approve(svtypeId) {
        if($.common.isEmpty(svtypeId)) {
            var status = $.table.selectColumns("svtypeStatus");
            if(status == 0 || status == 1) {
                $.modal.alertWarning("此状态无需审核");
            }else {
                $.modal.open("服务类型审核", prefix + "/approve?svtypeId="+$.table.selectColumns("svtypeId"));
            }
        }else {
            $.modal.open("服务类型审核", prefix + "/approve?svtypeId="+svtypeId);
        }
    }
</script>
</body>
</html>